"""
这是合同页面类
"""
from time import sleep

#引入基类
from framwork.pages.base_page import BasePage
#引入by方法
from selenium.webdriver.common.by import By
#引入断言失败异常
from selenium.common.exceptions import NoSuchElementException

class ContractPage(BasePage):
    """先写定位器，再写方法"""
    add_ht_locator = (By.CSS_SELECTOR, "a.btn.btn-primary")
    tips_success_locator = (By.CSS_SELECTOR, "body > div.container > div.alert.alert-success")
    edit_ht_locator = (By.LINK_TEXT, "编辑")
    ht_price_locator = (By.ID, "price")
    save_btn_locator = (By.CSS_SELECTOR, "input.btn.btn-primary")
    edit_success_locator = (By.CSS_SELECTOR, "#tab1 > div.back_box > div")
    check_list_locator = (By.NAME, "contract_id[]")
    delete_btn_locator = (By.ID, "delete")
    delete_success_locator = (By.CSS_SELECTOR, "body > div.container > div.alert.alert-success")

    def click_delete(self):
        '''点击删除按钮'''
        self.find_element(self.delete_btn_locator).click()

    def click_check_list(self):
        '''点击勾选全部'''
        self.find_element(self.check_list_locator).click()

    def click_save(self):
        '''点击保存'''
        self.find_element(self.save_btn_locator).click()

    def click_edit(self):
        '''点击编辑'''
        self.find_element(self.edit_ht_locator).click()

    def input_ht_price(self, ht_price):
        '''输入合同金额'''
        self.find_element(self.ht_price_locator).clear()
        sleep(2)
        self.find_element(self.ht_price_locator).send_keys(ht_price)

    def click_add_ht_btn(self):
        '''点击添加合同按钮'''
        self.find_element(self.add_ht_locator).click()

    def tips_success_text(self):
        '''添加合同成功断言文本'''
        try:
            text = self.find_element(self.tips_success_locator).text
        except NoSuchElementException:
            text = ""
        return text

    def edit_success_text(self):
        '''修改成功断言文本'''
        try:
            text = self.find_element(self.edit_success_locator).text
        except NoSuchElementException:
            text = ""
        return text

    def delete_success_text(self):
        '''删除成功断言文本'''
        try:
            text = self.find_element(self.delete_success_locator).text
        except NoSuchElementException:
            text = ""
        return text
